package com.leyou.order.controller;

import com.leyou.order.dto.OrderDTO;
import com.leyou.order.service.OrderService;
import com.leyou.order.vo.OrderVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author xiuer
 * @description
 * @create 2019/7/13 19:25
 */
@RestController
@RequestMapping("order")
public class OrderController {
    @Autowired
    private OrderService orderService;


    /**
     * http://api.leyou.com/api/order
     * 创建订单
     *
     * @param orderDTO 用户提交的订单数据
     * @return 订单的Id
     */
    @PostMapping
    public ResponseEntity<Long> insertOrder(@RequestBody OrderDTO orderDTO) {
        return ResponseEntity.status(HttpStatus.CREATED).body(orderService.insertOrder(orderDTO));
    }

    /**
     * 查询订单
     * http://api.leyou.com/api/order/1150378510574030848
     * Request Method: GET
     */
    @GetMapping("{orderId}")
    public ResponseEntity<OrderVO> queryOrderByOrderId(@PathVariable("orderId") Long orderId) {
        return ResponseEntity.ok(orderService.queryOrderByOrderId(orderId));
    }


}
